# encoding: utf-8
# @author: __匸匿
"""
@license: 980980524@qq.com,
@contact: qq:980980524
@file: image_storage.py
@time: 19-1-8 下午6:52
@desc:
"""
from qiniu import Auth, put_data

access_key = "hTSD6jLySAGFdd-VZfegvM4ZUc9ShcdSe_lKgf5T"
secret_key = "DJIp9bgXG_ZVCpFboPUVDS1wGYz4WwKZ69q0qAHe"
bucket_name = "test01"


def storage(data):
    try:
        q = Auth(access_key, secret_key)
        token = q.upload_token(bucket_name)
        ret, info = put_data(token, None, data)

        print(ret, info)
    except Exception as e:
        raise e

    if info.status_code != 200:
        raise Exception("图片下载失败")
    return ret["key"]

if __name__ == '__main__':
    file = input("路径")
    with open(file,"rb") as f:
        storage(f.read())